#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <net/if.h>
#include <netdb.h>

int main()
{
	int fds[2];
	int ret = socketpair(AF_UNIX, SOCK_SEQPACKET, 0, fds);
	if (ret < 0) {
		perror("socketpair");
		exit(0);
	}

	if (fork() == 0) {
		close(fds[0]);
		dup2(fds[1], 0);
		dup2(fds[1], 1);
		execlp("telnet", "telnet", "10.110.30.136", "23", NULL);
		perror("execl");
		exit(0);
	}

	close(fds[1]);
	char buf[1024];
	int len = 0;
	while ((len = read(fds[0], buf, sizeof(buf))) > 0) {
		buf[len] = 0;
		printf("%s", buf);
	}
	return 0;
}